package com.wpzf.ndhc.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.wpzf.common.core.utils.StringUtils;
import com.wpzf.common.core.utils.sign.Base64;
import com.wpzf.ndhc.domain.WpSjHcfjNdDTO;
import com.wpzf.ndhc.utils.GTYUtil;
import com.wpzf.ndhc.utils.TableUtil;
import com.wpzf.ndhc.domain.WpCjDkxxbDTO;
import com.wpzf.ndhc.domain.WpCjTbjtNdDTO;
import com.wpzf.ndhc.domain.WpCjTbxxbDTO;
import com.wpzf.ndhc.mapper.WpzfNdhcTbBaseMapper;
import com.wpzf.ndhc.service.WpzfNdhcTbBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;

@Service
public class WpzfNdhcTbBaseServiceImpl implements WpzfNdhcTbBaseService {

    @Autowired
    WpzfNdhcTbBaseMapper wpzfNdhcTbBaseMapper;


    @Override
    public Map<String, Object> queryUserByHctbId(Map<String, Object> parm) {
        parm = TableUtil.TableName(parm);
        return wpzfNdhcTbBaseMapper.queryUserByHctbId(parm);
    }

    @Override
    public WpCjDkxxbDTO querydkxxBytbbh(Map<String, Object> parm) {
        parm = TableUtil.TableName(parm);
        return wpzfNdhcTbBaseMapper.querydkxxBytbbh(parm);
    }


    @Override
    public List<WpCjTbxxbDTO> querytbxxBytbbh(Map<String, Object> parm) {
        parm = TableUtil.TableName(parm);
        return wpzfNdhcTbBaseMapper.querytbxxBytbbh(parm);
    }


    @Override
    public List<WpCjDkxxbDTO> querydkxxrelateBytbbh(Map<String, Object> parm) {
        parm = TableUtil.TableName(parm);
        String tbbh = parm.get("tbbh") + "";
        String jcbh = tbbh.split("-")[0];
        parm.put("jcbh", jcbh);
        return wpzfNdhcTbBaseMapper.getCftbList(parm);
    }

    @Override
    public ModelMap getShowImgs(Map<String, Object> parm) {
        ModelMap map = new ModelMap();
        try {
            String tbbhs = parm.get("tbbh") + "";
            String xzqdm = parm.get("xzqdm") + "";
            String pch = parm.get("pch") + "";
            String postURL = "";
            String data = "";
            String strXzqdm = parm.get("xzqdm").toString().substring(0, 2);
            {
                postURL = "https://jg.landcloud.org.cn:8553/webapi/token";
                data = "client_id=web&client_secret=e46232c20609435eba54b7576de935dd&grant_type=password&username=a53e0c14ee900728f36bba014d975982&password=b30c775c48e9ba92ade95e427a5242b0";
            }
            URL url = new URL(postURL);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");

            conn.setDoOutput(true);
            conn.setDoInput(true);
            OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "utf-8");

            out.write(data);
            //缓冲数据
            out.flush();
            //获取URLConnection对象对应的输入流
            InputStream is = conn.getInputStream();
            int count = 0;
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            byte[] buffer = new byte[4096];
            while ((count = is.read(buffer)) != -1) {
                byteArrayOutputStream.write(buffer, 0, count);
            }
            byte[] datas = byteArrayOutputStream.toByteArray();

            byteArrayOutputStream.close();
            //关闭流
            is.close();

            conn.disconnect();
            String result = new String(datas, 0, datas.length, "utf-8");
            List<String> items = new ArrayList<>();
            {
                String t = getImg(result, "00gty_wpzf_nddk", xzqdm, tbbhs);
                items.add(t);
                map.put("data", items);
            }
        } catch (MalformedURLException ex) {
            throw new RuntimeException(ex);
        } catch (UnsupportedEncodingException ex) {
            throw new RuntimeException(ex);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        return map;
    }

    @Override
    public List<WpCjTbjtNdDTO> querytbjtBytbbh(Map<String, Object> parm) {
        String tbbh = parm.get("tbbh").toString();
        String xzqdm = parm.get("xzqdm").toString();
        String pch = parm.get("pch").toString();
        String url = "";

        String xzq = parm.get("xzqdm").toString().substring(0, 2);
//        String dkbh = MyStringUtils.truncateString(tbbh);
        String jcbh = "";
        if (tbbh.indexOf(",") != -1) {
            String s = tbbh.split(",")[0];
            if (s.indexOf("-") != -1) {
                jcbh = s.substring(0, s.indexOf("-"));
            } else {
                jcbh = tbbh;
            }
        } else {
            if (tbbh.indexOf("-") != -1) {
                jcbh = tbbh.substring(0, tbbh.indexOf("-"));
            } else {
                jcbh = tbbh;
            }
        }

        List<WpCjTbjtNdDTO> lists = new ArrayList<>();
        WpCjTbjtNdDTO model = new WpCjTbjtNdDTO();
        model.setName("用地管理信息套合示意图");
        url = "https://obs-top.obs.cn-north-1.myhuaweicloud.com/upload/photo/wpzf2024/" + pch + "/" + xzq + "/" + xzqdm + "/" + jcbh + "_YDGL.jpg";
        model.setUrl(url);
        lists.add(model);

        model = new WpCjTbjtNdDTO();
        model.setName("耕地套合示意图");
        url = "https://obs-top.obs.cn-north-1.myhuaweicloud.com/upload/photo/wpzf2024/" + pch + "/" + xzq + "/" + xzqdm + "/" + jcbh + "_GD.jpg";
        model.setUrl(url);
        lists.add(model);

        model = new WpCjTbjtNdDTO();
        model.setName("设施农用地备案示意图");
        url = "https://obs-top.obs.cn-north-1.myhuaweicloud.com/upload/photo/wpzf2024/" + pch + "/" + xzq + "/" + xzqdm + "/" + jcbh + "_SSNYD.jpg";
        model.setUrl(url);
        lists.add(model);

        return lists;
    }

    public String getImg(String str, String ywmb, String xzqdm, String tbbh) {
        String rest = "";
        try {
            String postURL = "";
            String token = "";
            String token_type = "";
            Map mapType = JSON.parseObject(str, Map.class);
            {
                for (Object obj : mapType.keySet()) {

                    if ((obj + "").equals("access_token")) {
                        token = mapType.get("access_token") + "";
                        token_type = mapType.get("token_type") + "";
                    }
                }
                System.out.println(token);
                //接口地址
                postURL = "https://dc2.landcloud.org.cn:9443/webapi/api/open/GetWPZFTBInfo";
            }
            URL url = new URL(postURL);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            String encoding = Base64.encode(str.getBytes());
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("Charset", "utf-8");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
            conn.setRequestProperty("Content-Type", "application/json;charset=utf-8 ");
            conn.setRequestProperty("Authorization", token_type + " " + token);
            //  conn.setRequestProperty("token", token);
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setConnectTimeout(2000);
            conn.setReadTimeout(2000);
            //获取URLConnection对象对应的输出流
            OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "utf-8");
            //  out = new PrintWriter(conn.getOutputStream());
            //发送请求参数即数据
            //String xmbh="210115S120240216LJ00005";
            if (StringUtils.isNotBlank(xzqdm)) {
                //String data = "{\"xzqdm\":\"" + xzqdm + "\",\"ywmb\":\"" + ywmb + "\"}";
                String data = "{\"xzqdm\":\"" + xzqdm + "\",\"ywmb\":\"" + ywmb + "\",\"xmbh\":[\"" + tbbh + "\"]}";
                System.out.println("---------获取地块列表参数------" + data);
                out.write(data);
                out.flush();
                InputStream is = conn.getInputStream();
                int count = 0;
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                byte[] buffer = new byte[4096];
                while ((count = is.read(buffer)) != -1) {
                    byteArrayOutputStream.write(buffer, 0, count);
                }
                byte[] datas = byteArrayOutputStream.toByteArray();

                byteArrayOutputStream.close();
                is.close();
                conn.disconnect();
                rest = new String(datas, 0, datas.length, "utf-8");
            }

        } catch (Exception e) {
            rest = "网络异常，请稍后重试！";
            //writeLog(UtilTool.GetTime_1()+"："+e.getMessage()+"\n");
            throw new RuntimeException(e.getMessage());
        }
        return rest;
    }

    @Override
    public List<WpCjTbjtNdDTO> getTbjtByHyjgurl(String parm) {
        System.out.println(parm);
        parm = parm.substring(1, parm.length() - 1);
        List<WpCjTbjtNdDTO> wpCjTbjtNdDTOList = new ArrayList<>();
        String[] array = parm.split(",");
        for (String s : array) {
            WpCjTbjtNdDTO wpCjTbjtNdDTO = new WpCjTbjtNdDTO();
            s = s.substring(1, s.length() - 1);
            if (s.indexOf("GD") != -1) {
                wpCjTbjtNdDTO.setName("耕地套合示意图");
                wpCjTbjtNdDTO.setUrl(s);
            } else if (s.indexOf("SSNYD") != -1) {
                wpCjTbjtNdDTO.setName("设施农用地备案示意图");
                wpCjTbjtNdDTO.setUrl(s);
            } else if (s.indexOf("YDGL") != -1) {
                wpCjTbjtNdDTO.setName("用地管理信息套合示意图");
                wpCjTbjtNdDTO.setUrl(s);
            } else {
                break;
            }
            wpCjTbjtNdDTOList.add(wpCjTbjtNdDTO);
        }

        return wpCjTbjtNdDTOList;
    }


    @Override
    public List<Map<String, Object>> getPch(Map<String, Object> param) {
        return wpzfNdhcTbBaseMapper.getPch(param);
    }

    @Override
    public List<Map<String, Object>> getShi(Map<String, Object> param) {
        return wpzfNdhcTbBaseMapper.getShi(param);
    }

    @Override
    public List<Map<String, Object>> getXian(Map<String, Object> param) {
        return wpzfNdhcTbBaseMapper.getXian(param);
    }

    @Override
    public List<Map<String, Object>> queryTbList(Map<String, Object> param) {
        return wpzfNdhcTbBaseMapper.queryTbList(param);
    }

    @Override
    public Integer queryTbListCount(Map<String, Object> param) {
        return wpzfNdhcTbBaseMapper.queryTbListCount(param);
    }

    @Override
    public Map<String, Object> queryTbByIndex(Map<String, Object> param) {
        return wpzfNdhcTbBaseMapper.queryTbByIndex(param);
    }

    @Override
    public Map<String, Object> queryTbInfoByTbbsm(Map<String, Object> param) {
        return wpzfNdhcTbBaseMapper.queryTbInfoByTbbsm(param);
    }

    @Override
    public List<Map<String, Object>> queryDkInfoByTbbsm(Map<String, Object> param) {
        return wpzfNdhcTbBaseMapper.queryDkInfoByTbbsm(param);
    }

    @Override
    public List<WpSjHcfjNdDTO> querySjHcfjByDkbsm(List<Map<String, Object>> param) {
        return wpzfNdhcTbBaseMapper.querySjHcfjByDkbsm(param);
    }

    @Override
    public Map<String, Object> queryDkDetails(Map<String, Object> param) {
        Map<String, Object> rest = new HashMap<>();

        //图斑信息
        Map<String, Object> tbInfo = wpzfNdhcTbBaseMapper.queryTbInfo(param);
        rest.put("tbInfo", tbInfo);

        //核查附件
        String token = GTYUtil.getGTYToken();
        String gtyRest = GTYUtil.getNDDxxxbsj2024(token, "00gty_wpzfnddk2024", param.get("xzqdm") + "", param.get("dkbh") + "");
//        String gtyRest = "{\"data\":[{\"main\":{\"wpzfdk\":{\"tbbsm\":\"5abb617ee90841de9243f2dbf488d67d\",\"tbbh\":\"360733WPXZ00005\",\"dkbh\":\"360733202502040048\",\"sjtbmj\":2.53,\"jcrq\":\"20250204\",\"xzqdm\":\"360733\",\"tbfl\":\"\",\"xzmc\":\"\",\"csmc\":\"\",\"xxdz\":\"\",\"geometry\":\"POLYGON((115.729701926373 25.2851165121866,115.729761116962 25.2851147054877,115.729761271504 25.2851147366032,115.729777773608 25.2850732945253,115.72983880291 25.2848935575449,115.730106084189 25.2841063847249,115.730027284762 25.2840867162887,115.729915705578 25.2840616074065,115.729901503149 25.2840584118763,115.729897034441 25.2840574058465,115.729876939116 25.2840528824405,115.729835574131 25.2840895786642,115.730044936843 25.2841562660705,115.730050494084 25.2842279555255,115.729995991245 25.284316321931,115.729846818864 25.2844153368094,115.729719768413 25.2845088097859,115.729713366777 25.2845212471537,115.729630349082 25.2846825348194,115.729627610598 25.2846932581546,115.729620633806 25.2847326007303,115.729626839436 25.2847672813208,115.729642336465 25.2847924891076,115.729660596854 25.2848045864702,115.729672377962 25.2848082702256,115.72975932456 25.2849475979182,115.729764971193 25.28501069115,115.729701926373 25.2851165121866))\",\"gdmj\":2.4,\"qtnydmj\":0.13,\"jsydmj\":0.0,\"wlydmj\":0.0,\"hcjl\":\"\",\"sfjsyd\":\"Y\",\"sfnrhsqd\":\"Y\",\"tblx\":\"HFYD\",\"sjyt\":\"01\",\"sjyt2\":\"\",\"hfsjyt\":\"0601\",\"hfpdyjsm\":\"\",\"wflx1\":\"\",\"wflx2\":\"\",\"wfsjyt\":\"\",\"lzgdjf\":\"\",\"sywhzj\":\"\",\"sfdpf\":\"\",\"wfpdyjsm\":\"\",\"wf_xmlx\":\"\",\"wf_xmzt\":\"\",\"wf_xmmc\":\"\",\"wf_lxpzjg\":\"\",\"wf_lxpzwh\":\"\",\"wf_sfla\":\"\",\"qtydsjyt\":\"\",\"qtydsjyt2\":\"\",\"pwsj\":\"\",\"qtpdyjsm\":\"\",\"nrqduserlevel\":2}},\"other\":{\"hcfj\":[{\"bsm\":58330544,\"xzqdm\":\"360733\",\"tbbsm\":\"5abb617ee90841de9243f2dbf488d67d\",\"tbbh\":\"360733WPXZ00005\",\"fjmc\":\"https://gdhc-gj-012035.obs.cn-north-1.myhuaweicloud.com/G/360733/NDBG2024/406f6420b5fe4d9e838691770ffdf48e/EDB9229963D74511979A3A7EC4D4EAA0F6DF822B4AA1A572F6AD96FDC042A82C_8532297376052868952.jpg\",\"lysb\":\"\",\"fjlx\":\"IMAGE\",\"psry\":\"范小三\",\"pssj\":\"2025-01-15 09:01:50\",\"longitude\":115.729678,\"latitude\":25.285091,\"psjd\":23,\"psgd\":\"229\",\"psfyj\":-23,\"psaltitude\":\"\",\"takeofflon\":\"\",\"takeofflat\":\"\",\"takeoffrelheight\":\"\",\"takeoffaltitude\":\"\",\"metarecord\":\"[{ \\\"accuracy\\\":3,\\\"x\\\":115.729678,\\\"y\\\":25.285091,\\\"yaw\\\":23,\\\"pitch\\\":-23,\\\"roll\\\":-1,\\\"distance\\\":\\\"\\\",\\\"height\\\":229}] \",\"arg\":\"EDB9229963D74511979A3A7EC4D4EAA0F6DF822B4AA1A572F6AD96FDC042A82C\",\"url\":\"https://gdhc-gj-012035.obs.cn-north-1.myhuaweicloud.com/G/360733/NDBG2024/406f6420b5fe4d9e838691770ffdf48e/EDB9229963D74511979A3A7EC4D4EAA0F6DF822B4AA1A572F6AD96FDC042A82C_8532297376052868952.jpg\"},{\"bsm\":58330543,\"xzqdm\":\"360733\",\"tbbsm\":\"5abb617ee90841de9243f2dbf488d67d\",\"tbbh\":\"360733WPXZ00005\",\"fjmc\":\"https://gdhc-gj-012035.obs.cn-north-1.myhuaweicloud.com/G/360733/NDBG2024/406f6420b5fe4d9e838691770ffdf48e/BFEDB99F451C03C4F05BE75AF14F3E320D34FB99AC9032FFD153CD4CC2A61038_8532297377752602252.jpg\",\"lysb\":\"\",\"fjlx\":\"IMAGE\",\"psry\":\"范小三\",\"pssj\":\"2025-01-15 09:01:06\",\"longitude\":115.72962,\"latitude\":25.2852535,\"psjd\":139,\"psgd\":\"226.18\",\"psfyj\":-12,\"psaltitude\":\"\",\"takeofflon\":\"\",\"takeofflat\":\"\",\"takeoffrelheight\":\"\",\"takeoffaltitude\":\"\",\"metarecord\":\"[{ \\\"accuracy\\\":3,\\\"x\\\":115.72962,\\\"y\\\":25.2852535,\\\"yaw\\\":139,\\\"pitch\\\":-12,\\\"roll\\\":-4,\\\"distance\\\":\\\"\\\",\\\"height\\\":226.18}] \",\"arg\":\"BFEDB99F451C03C4F05BE75AF14F3E320D34FB99AC9032FFD153CD4CC2A61038\",\"url\":\"https://gdhc-gj-012035.obs.cn-north-1.myhuaweicloud.com/G/360733/NDBG2024/406f6420b5fe4d9e838691770ffdf48e/BFEDB99F451C03C4F05BE75AF14F3E320D34FB99AC9032FFD153CD4CC2A61038_8532297377752602252.jpg\"},{\"bsm\":58330542,\"xzqdm\":\"360733\",\"tbbsm\":\"5abb617ee90841de9243f2dbf488d67d\",\"tbbh\":\"360733WPXZ00005\",\"fjmc\":\"https://gdhc-gj-012035.obs.cn-north-1.myhuaweicloud.com/G/360733/NDBG2024/406f6420b5fe4d9e838691770ffdf48e/40744840EF179FFABBB759D870CF14435700652DC8CEF6DAEF5E638A2FEE3111_8532297379111864052.jpg\",\"lysb\":\"\",\"fjlx\":\"IMAGE\",\"psry\":\"范小三\",\"pssj\":\"2025-01-15 09:01:46\",\"longitude\":115.729749,\"latitude\":25.285108,\"psjd\":335,\"psgd\":\"225.96\",\"psfyj\":-9,\"psaltitude\":\"\",\"takeofflon\":\"\",\"takeofflat\":\"\",\"takeoffrelheight\":\"\",\"takeoffaltitude\":\"\",\"metarecord\":\"[{ \\\"accuracy\\\":3,\\\"x\\\":115.729749,\\\"y\\\":25.285108,\\\"yaw\\\":335,\\\"pitch\\\":-9,\\\"roll\\\":-3,\\\"distance\\\":\\\"\\\",\\\"height\\\":225.96}] \",\"arg\":\"40744840EF179FFABBB759D870CF14435700652DC8CEF6DAEF5E638A2FEE3111\",\"url\":\"https://gdhc-gj-012035.obs.cn-north-1.myhuaweicloud.com/G/360733/NDBG2024/406f6420b5fe4d9e838691770ffdf48e/40744840EF179FFABBB759D870CF14435700652DC8CEF6DAEF5E638A2FEE3111_8532297379111864052.jpg\"},{\"bsm\":58330541,\"xzqdm\":\"360733\",\"tbbsm\":\"5abb617ee90841de9243f2dbf488d67d\",\"tbbh\":\"360733WPXZ00005\",\"fjmc\":\"https://gdhc-gj-012035.obs.cn-north-1.myhuaweicloud.com/G/360733/NDBG2024/406f6420b5fe4d9e838691770ffdf48e/2D181952D3CC1F26C7DFB3B904DCA91ECE52D725A5EC8E21AD48EDE127057D62_8532297378667584552.jpg\",\"lysb\":\"\",\"fjlx\":\"IMAGE\",\"psry\":\"范小三\",\"pssj\":\"2025-01-15 09:01:48\",\"longitude\":115.7296856,\"latitude\":25.2852781,\"psjd\":182,\"psgd\":\"225.65\",\"psfyj\":3,\"psaltitude\":\"\",\"takeofflon\":\"\",\"takeofflat\":\"\",\"takeoffrelheight\":\"\",\"takeoffaltitude\":\"\",\"metarecord\":\"[{ \\\"accuracy\\\":3,\\\"x\\\":115.7296856,\\\"y\\\":25.2852781,\\\"yaw\\\":182,\\\"pitch\\\":3,\\\"roll\\\":2,\\\"distance\\\":\\\"\\\",\\\"height\\\":225.65}] \",\"arg\":\"2D181952D3CC1F26C7DFB3B904DCA91ECE52D725A5EC8E21AD48EDE127057D62\",\"url\":\"https://gdhc-gj-012035.obs.cn-north-1.myhuaweicloud.com/G/360733/NDBG2024/406f6420b5fe4d9e838691770ffdf48e/2D181952D3CC1F26C7DFB3B904DCA91ECE52D725A5EC8E21AD48EDE127057D62_8532297378667584552.jpg\"}],\"pwinfo\":[{\"pwtbbsm\":\"f123cb98b97c5d6bac89431aa5b26122\",\"pzwhlx\":\"NYDZY\",\"pzwhlxtwo\":\"\",\"pwlb\":\"\",\"pzwh\":\"赣土批字（2022）257号\",\"pzsj\":\"2022-10-08 00:00:00\",\"pwly\":\"2\",\"pzmj\":230.93,\"pznydmj\":220.69,\"pzgdmj\":148.61,\"pzyjjbntmj\":0.0,\"reason\":\"\",\"pzjg\":\"江西省人民政府\"}],\"fjinfo\":[{\"tbbsm\":\"5abb617ee90841de9243f2dbf488d67d\",\"pwtbbsm\":\"f123cb98b97c5d6bac89431aa5b26122\",\"fjmc\":\"关于会昌县2022年度第3批次城市建设用地的批复.pdf\",\"fjurl\":\"https://gdhc-gj-012035.obs.cn-north-1.myhuaweicloud.com/G/360733/fjData/56cdb1b570274ee785278d546ba51b23/56cdb1b570274ee785278d546ba51b23/9f985982-bb99-855c-6709-c595e3b040fa_8532352841267112252.pdf\",\"fjlx\":\"PWPDYJ\"},{\"tbbsm\":\"5abb617ee90841de9243f2dbf488d67d\",\"pwtbbsm\":\"\",\"fjmc\":\"报批套合图_360733WPXZ00005.pdf\",\"fjurl\":\"https://gdhc-gj-012035.obs.cn-north-1.myhuaweicloud.com/G/360733/fjData/5abb617ee90841de9243f2dbf488d67d/5abb617ee90841de9243f2dbf488d67d/be284ff3-1ec3-1666-a1b3-b18551a726cd_8534187211922832152.pdf\",\"fjlx\":\"FJZL\"}]}}],\"total\":1,\"code\":200,\"status\":0,\"error\":null,\"message\":null}";
        rest.put("gtyRest", gtyRest);

        JSONArray hcfj = new JSONArray();
        JSONArray pwinfo = new JSONArray();
        JSONArray fjinfo = new JSONArray();
        JSONObject wpzfdk = new JSONObject();

        JSONObject jsonObject = JSONObject.parseObject(gtyRest);
        JSONArray dataArray = jsonObject.getJSONArray("data");
        if (dataArray != null && dataArray.size() > 0) {
            JSONObject data = dataArray.getJSONObject(0);
            JSONObject other = data.getJSONObject("other");
            hcfj = other.getJSONArray("hcfj");
            pwinfo = other.getJSONArray("pwinfo");
            fjinfo = other.getJSONArray("fjinfo");

            JSONObject main = data.getJSONObject("main");
            wpzfdk = main.getJSONObject("wpzfdk");
        }

        //地块信息
        Map<String, Object> dkInfo = wpzfNdhcTbBaseMapper.queryDkInfo(param);

        if (dkInfo != null && wpzfdk != null) {
            dkInfo.put("dkfw", wpzfdk.getString("geometry"));
            dkInfo.put("sfnrhsqd", wpzfdk.getString("sfnrhsqd"));
            dkInfo.put("sfnrhsqdmc", yesNoDictionary(wpzfdk.getString("sfnrhsqd")));
            dkInfo.put("hf_jtqx1", wpzfdk.getString("sjyt"));
            dkInfo.put("hf_jtqx1mc", hfjtqx1Dictionary(wpzfdk.getString("sjyt")));
            dkInfo.put("hf_jtqx2", wpzfdk.getString("sjyt2"));
            dkInfo.put("hf_jtqx2mc", hfjtqx2Dictionary(wpzfdk.getString("sjyt2")));
            dkInfo.put("hf_sjyt", wpzfdk.getString("hfsjyt"));
            dkInfo.put("hf_sjytmc", hfsjytDictionary(wpzfdk.getString("hfsjyt")));
            dkInfo.put("hf_pdyjsm", wpzfdk.getString("hfpdyjsm"));
            dkInfo.put("wf_wflx1", wpzfdk.getString("wflx1"));
            dkInfo.put("wf_wflx1mc", wflx1Dictionary(wpzfdk.getString("wflx1")));
            dkInfo.put("wf_wflx2", wpzfdk.getString("wflx2"));
            dkInfo.put("wf_wflx2mc", wflx2Dictionary(wpzfdk.getString("wflx2")));
            dkInfo.put("wf_sjyt", wpzfdk.getString("wfsjyt"));
            dkInfo.put("wf_sjytmc", wfsjytDictionary(wpzfdk.getString("wfsjyt")));
            dkInfo.put("sflzgdjf", wpzfdk.getString("lzgdjf"));
            dkInfo.put("sflzgdjfmc", yesNoDictionary(wpzfdk.getString("lzgdjf")));
            dkInfo.put("sfwhzj", wpzfdk.getString("sywhzj"));
            dkInfo.put("sfwhzjmc", yesNoDictionary(wpzfdk.getString("sywhzj")));
            dkInfo.put("sfdpf", wpzfdk.getString("sfdpf"));
            dkInfo.put("sfdpfmc", yesNoDictionary(wpzfdk.getString("sfdpf")));
            dkInfo.put("wf_pdyjsm", wpzfdk.getString("wfpdyjsm"));
            dkInfo.put("xmmc", wpzfdk.getString("wf_xmmc"));
            dkInfo.put("xmzt", wpzfdk.getString("wf_xmzt"));
            dkInfo.put("xmlx", wpzfdk.getString("wf_xmlx"));
            dkInfo.put("xmlxmc", xmlxDictionary(wpzfdk.getString("wf_xmlx")));
            dkInfo.put("lxpzjg", wpzfdk.getString("wf_lxpzjg"));
            dkInfo.put("lxpzwh", wpzfdk.getString("wf_lxpzwh"));
            dkInfo.put("wf_sfla", wpzfdk.getString("wf_sfla"));
            dkInfo.put("wf_sflamc", yesNoDictionary(wpzfdk.getString("wf_sfla")));
            dkInfo.put("qt_jtqx1", wpzfdk.getString("qtydsjyt"));
            dkInfo.put("qt_jtqx1mc", qtjtqx1Dictionary(wpzfdk.getString("qtydsjyt")));
            dkInfo.put("qt_jtqx2", wpzfdk.getString("qtydsjyt2"));
            dkInfo.put("qt_jtqx2mc", qtjtqx2Dictionary(wpzfdk.getString("qtydsjyt2")));
            dkInfo.put("pwsj", wpzfdk.getString("pwsj"));
            dkInfo.put("pwsjmc", pwsjDictionary(wpzfdk.getString("pwsj")));
            dkInfo.put("qt_pdyjsm", wpzfdk.getString("qtpdyjsm"));

            dkInfo.put("xzjd", wpzfdk.getString("xzmc"));
            dkInfo.put("csmc", wpzfdk.getString("csmc"));
            dkInfo.put("xxdz", wpzfdk.getString("xxdz"));
            dkInfo.put("nrqduserlevel", wpzfdk.getInteger("nrqduserlevel"));
        }
        rest.put("dkInfo", dkInfo);

        rest.put("hcfj", hcfj);
        rest.put("pwinfo", pwinfo);
        rest.put("fjinfo", fjinfo);

        //单位结果
        param.put("ywhj", "0");
        Map<String, Object> hcdwResultInfo = queryTbhcjg(param);
        rest.put("hcdwResultInfo", hcdwResultInfo);

        //监理结果
        param.put("ywhj", "1");
        Map<String, Object> jlhcResultInfo = queryTbhcjg(param);
        rest.put("jlhcResultInfo", jlhcResultInfo);

        //监理结果确认
        param.put("ywhj", "2");
        Map<String, Object> jljgqrResultInfo = queryTbhcjg(param);
        rest.put("jljgqrResultInfo", jljgqrResultInfo);

        //整改
        param.put("ywhj", "3");
        Map<String, Object> zgResultInfo = queryTbhcjg(param);
        rest.put("zgResultInfo", zgResultInfo);

        //审核
        Map<String, Object> shResultInfo = queryShTbhcjg(param);
        rest.put("shResultInfo", shResultInfo);

        //第三方监督
        Map<String, Object> dsfjdResultInfo = queryDsfjdTbhcjg(param);
        rest.put("dsfjdResultInfo", dsfjdResultInfo);

        //国土云token
        rest.put("gtyToken", GTYUtil.getGTYToken());
        return rest;
    }

    public Map<String, Object> queryTbhcjg(Map<String, Object> param) {
        Map<String, Object> resultInfo = wpzfNdhcTbBaseMapper.queryTbhcjg(param);
        if (resultInfo != null && resultInfo.size() > 0) {
            List<Map<String, Object>> hftgzmwjList = wpzfNdhcTbBaseMapper.queryHftgzmwj(param);
            List<Map<String, Object>> qtpzwhList = wpzfNdhcTbBaseMapper.queryQtpzwh(param);
            List<Map<String, Object>> qtsftgxxydssList = wpzfNdhcTbBaseMapper.queryQtsftgxxydss(param);
            List<Map<String, Object>> qtsfzygList = wpzfNdhcTbBaseMapper.queryQtsfzyg(param);
            List<Map<String, Object>> wfpzwhList = wpzfNdhcTbBaseMapper.queryWfpzwh(param);
            List<Map<String, Object>> wftgzmwjList = wpzfNdhcTbBaseMapper.queryWftgzmwj(param);
            resultInfo.put("hftgzmwjList", hftgzmwjList);
            resultInfo.put("qtpzwhList", qtpzwhList);
            resultInfo.put("qtsftgxxydssList", qtsftgxxydssList);
            resultInfo.put("qtsfzygList", qtsfzygList);
            resultInfo.put("wfpzwhList", wfpzwhList);
            resultInfo.put("wftgzmwjList", wftgzmwjList);
        }
        return resultInfo;
    }

    public Map<String, Object> queryShTbhcjg(Map<String, Object> param) {
        Map<String, Object> resultInfo = wpzfNdhcTbBaseMapper.queryShTbhcjg(param);
        if (resultInfo != null && resultInfo.size() > 0) {
            List<Map<String, Object>> hftgzmwjList = wpzfNdhcTbBaseMapper.queryHftgzmwj(resultInfo);
            List<Map<String, Object>> qtpzwhList = wpzfNdhcTbBaseMapper.queryQtpzwh(resultInfo);
            List<Map<String, Object>> qtsftgxxydssList = wpzfNdhcTbBaseMapper.queryQtsftgxxydss(resultInfo);
            List<Map<String, Object>> qtsfzygList = wpzfNdhcTbBaseMapper.queryQtsfzyg(resultInfo);
            List<Map<String, Object>> wfpzwhList = wpzfNdhcTbBaseMapper.queryWfpzwh(resultInfo);
            List<Map<String, Object>> wftgzmwjList = wpzfNdhcTbBaseMapper.queryWftgzmwj(resultInfo);
            resultInfo.put("hftgzmwjList", hftgzmwjList);
            resultInfo.put("qtpzwhList", qtpzwhList);
            resultInfo.put("qtsftgxxydssList", qtsftgxxydssList);
            resultInfo.put("qtsfzygList", qtsfzygList);
            resultInfo.put("wfpzwhList", wfpzwhList);
            resultInfo.put("wftgzmwjList", wftgzmwjList);
        }
        return resultInfo;
    }

    public Map<String, Object> queryDsfjdTbhcjg(Map<String, Object> param) {
        Map<String, Object> resultInfo = wpzfNdhcTbBaseMapper.queryDsfjdTbhcjg(param);
        if (resultInfo != null && resultInfo.size() > 0) {
            List<Map<String, Object>> hftgzmwjList = wpzfNdhcTbBaseMapper.queryDsfjdHftgzmwj(resultInfo);
            List<Map<String, Object>> qtpzwhList = wpzfNdhcTbBaseMapper.queryDsfjdQtpzwh(resultInfo);
            List<Map<String, Object>> qtsftgxxydssList = wpzfNdhcTbBaseMapper.queryDsfjdQtsftgxxydss(resultInfo);
            List<Map<String, Object>> qtsfzygList = wpzfNdhcTbBaseMapper.queryDsfjdQtsfzyg(resultInfo);
            List<Map<String, Object>> wfpzwhList = wpzfNdhcTbBaseMapper.queryDsfjdWfpzwh(resultInfo);
            List<Map<String, Object>> wftgzmwjList = wpzfNdhcTbBaseMapper.queryDsfjdWftgzmwj(resultInfo);
            resultInfo.put("hftgzmwjList", hftgzmwjList);
            resultInfo.put("qtpzwhList", qtpzwhList);
            resultInfo.put("qtsftgxxydssList", qtsftgxxydssList);
            resultInfo.put("qtsfzygList", qtsfzygList);
            resultInfo.put("wfpzwhList", wfpzwhList);
            resultInfo.put("wftgzmwjList", wftgzmwjList);
        }
        return resultInfo;
    }

    public String yesNoDictionary(String param) {
        Map<String, Object> map = wpzfNdhcTbBaseMapper.queryYesnoByKey(param);
        return map != null ? map.get("value") + "" : null;
    }

    public String hfjtqx1Dictionary(String param) {
        Map<String, Object> map = wpzfNdhcTbBaseMapper.queryHfjtqx1ByKey(param);
        return map != null ? map.get("value") + "" : null;
    }

    public String hfjtqx2Dictionary(String param) {
        Map<String, Object> map = wpzfNdhcTbBaseMapper.queryHfjtqx2ByKey(param);
        return map != null ? map.get("value") + "" : null;
    }

    public String hfsjytDictionary(String param) {
        Map<String, Object> map = wpzfNdhcTbBaseMapper.queryHfsjytByKey(param);
        return map != null ? map.get("value") + "" : null;
    }

    public String wflx1Dictionary(String param) {
        Map<String, Object> map = wpzfNdhcTbBaseMapper.queryWflx1ByKey(param);
        return map != null ? map.get("value") + "" : null;
    }

    public String wflx2Dictionary(String param) {
        Map<String, Object> map = wpzfNdhcTbBaseMapper.queryWflx2ByKey(param);
        return map != null ? map.get("value") + "" : null;
    }

    public String wfsjytDictionary(String param) {
        Map<String, Object> map = wpzfNdhcTbBaseMapper.queryWfsjytByKey(param);
        return map != null ? map.get("value") + "" : null;
    }

    public String xmlxDictionary(String param) {
        Map<String, Object> map = wpzfNdhcTbBaseMapper.queryXmlxByKey(param);
        return map != null ? map.get("value") + "" : null;
    }

    public String qtjtqx1Dictionary(String param) {
        Map<String, Object> map = wpzfNdhcTbBaseMapper.queryQtjtqx1ByKey(param);
        return map != null ? map.get("value") + "" : null;
    }

    public String qtjtqx2Dictionary(String param) {
        Map<String, Object> map = wpzfNdhcTbBaseMapper.queryQtjtqx2ByKey(param);
        return map != null ? map.get("value") + "" : null;
    }

    public String pwsjDictionary(String param) {
        Map<String, Object> map = wpzfNdhcTbBaseMapper.queryPwsjByKey(param);
        return map != null ? map.get("value") + "" : null;
    }


}

